﻿using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Trippy.CollidableGameComponents;
using Trippy.CollidableGameComponents.Agents;
using Trippy.Levels;

namespace Trippy.Abilities
{
    public class Jump : Ability
    {
        public Jump(Level level) : base(level)

        {
            State = AbilityState.Available;
            name = "Jump";
            icon = CurrentLevel.Game.Content.Load<Texture2D>("Sprites/Ability Icons/jump");
        }
        public override void OnActivate()
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Grounded)
            {
                CurrentLevel.Hero.Jump();
            }
            else if (State == AbilityState.Available)
            {
                State = AbilityState.Unavailable;
                CurrentLevel.Hero.Velocity = new Vector2(CurrentLevel.Hero.Velocity.X, 0.0f); //changed because double jump when falling wasn't doing anything.
                                                                                              //now stalls vertical velocity then jumps.
                CurrentLevel.Hero.Jump();
            }
            base.OnActivate();
        }

        public override void OnJump()
        {
            if (CurrentLevel.Hero.State == Hero.HeroState.Jumping)
                OnActivate();
            base.OnJump();
        }

        public override void OnLand()
        {
            State = AbilityState.Available;
            base.OnLand();
        }
    }

    public class OneTimeJump : Jump
    {
        public OneTimeJump(Level level)
            : base(level)
        {
        }
        public override void OnActivate()
        {
            if(State == AbilityState.Available
                && CurrentLevel.Hero.State == Hero.HeroState.Jumping)
                CurrentLevel.Hero.RestoreAbility(); //remove ourselves on first use, give player back prev ability.
            base.OnActivate();
        }
        public override void OnDraw(SpriteBatch sb, Rectangle r)
        {
            base.OnDraw(sb, r);
            sb.DrawString(font, "1", new Vector2(r.X + 7, r.Y + r.Height - 20), CurrentLevel.UIColor);
        }
    }
}
